package net.zjitc.controller;

import net.zjitc.pojp.AdminUser;

import net.zjitc.service.LoginService;
import net.zjitc.service.UserService;
import net.zjitc.service.impl.LoginServiceImpl;
import net.zjitc.service.impl.UserServiceImpl;
import net.zjitc.utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/11/15.
 */
public class LoginController {
    LoginService loginService=new LoginServiceImpl();
    @URLMapping(url = "/login")
    public String login(HttpServletRequest request, HttpServletResponse response) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        AdminUser adminUser = loginService.findByUsernameAndPassWord(username, password);
        if (adminUser == null) {
            return "/admin/login.jsp";
        }
        HttpSession session=request.getSession();
        session.setAttribute("adminUser",adminUser);
        return "Redirect:" + request.getContextPath() + "/admin/home.jsp";

    }
}
